package cn.sccl.common.model;

import java.util.ArrayList;

/**
 * 分页查询的返回结果
 * Created by 杨浩宇 on 2016-02-15.
 */
public class Page<E> extends ArrayList<E> {

    private long pageSize = 20;//每页记录数

    private long total = 0;//总记录数

    private long start;//当前页第一条记录在数据库中的序号，从0开始

    public Page() {

    }

    public static Page newInstance(long pageIndex, long pageSize) {
        Page page = new Page();
        page.setStart((pageIndex - 1) * pageSize);
        page.setPageSize(pageSize);
        return page;
    }

    public long getPageCount() {
        if (total % pageSize == 0) {
            return total / pageSize;
        } else {
            return total / pageSize + 1;
        }
    }

    public long getPageIndex() {
        return start / pageSize + 1;
    }

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public long getStart() {
        return start;
    }

    public void setStart(long start) {
        this.start = start;
    }

    @Override
    public Page clone() {
        Page page = new Page();
        page.setStart(this.getStart());
        page.setPageSize(this.getPageSize());
        page.setTotal(this.getTotal());
        return page;
    }
}
